package com.assist.service.impl;

import org.hibernate.Session;

import com.assist.dao.IUserDAO;
import com.assist.dao.impl.UserDAOImpl;
import com.assist.model.User;
import com.assist.service.IUserService;
import com.assist.util.HibernateUtil;

public class UserServiceImpl implements IUserService {

	IUserDAO userDAO = new UserDAOImpl();

	public boolean saveOrUpdateUser(User user) {
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();
			userDAO.saveOrUpdateUser(user);
			session.getTransaction().commit();
			return true;
		} catch (Exception e) {
			return false;
		}

	}

	public User getUser(String userName, String password) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		User user = userDAO.getUser(userName, password);
		session.getTransaction().commit();
		
		return user;
	}

	public User getUserById(long userId) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		User user = userDAO.getUserById(userId);
		session.getTransaction().commit();
		
		return user;
	}
}
